using System.Collections.Generic;
using UnityEngine;
using MintAnimation;
using MintAnimation.Core;

public class MintAnimationsPlay : MonoBehaviour
{
    public bool isReverseContinuation = false;
    public List<MintAnimationComponent> mints;

    private bool isReversal;
    private bool isInitReversal = false;

    public void MintPlay(bool isReversal, bool playEndDisable)
    {
        for (int i = 0; i < mints.Count; ++i)
        {
            if (mints[i].enabled)
            {
                if (!isInitReversal) { this.isReversal = isReversal; isInitReversal = true; }
                if (!mints[i].gameObject.activeSelf) mints[i].gameObject.SetActive(true);
                if (isReverseContinuation)
                {
                    if (!mints[i].IsEnd() && this.isReversal != isReversal)
                    {
                        mints[i].CompleteAction = playEndDisable ? PlayEndAction.Disable : PlayEndAction.None;
                        mints[i].ReverseContinuation();
                        continue;
                    }
                }
                else
                {
                    mints[i].Stop();
                }
                mints[i].GetOptions().IsReversal = isReversal;
                mints[i].CompleteAction = playEndDisable ? PlayEndAction.Disable : PlayEndAction.None;
                mints[i].Play();
                this.isReversal = isReversal;
            }
        }
    }

    public void MintPlay(bool isReversal)
    {
        for (int i = 0; i < mints.Count; ++i)
        {
            if (mints[i].enabled)
            {
                if (!isInitReversal) { this.isReversal = isReversal; isInitReversal = true; }
                if (!mints[i].gameObject.activeSelf) mints[i].gameObject.SetActive(true);
                if (isReverseContinuation)
                {
                    if (!mints[i].IsEnd() && this.isReversal != isReversal)
                    {
                        mints[i].ReverseContinuation();
                        continue;
                    }
                }
                else
                {
                    mints[i].Stop();
                }
                mints[i].GetOptions().IsReversal = isReversal;
                mints[i].CompleteAction = PlayEndAction.None;
                mints[i].Play();
                this.isReversal = isReversal;
            }
        }
    }

    public void MintStop(bool isReversal)
    {
        for (int i = 0; i < mints.Count; ++i)
        {
            if (mints[i].enabled)
            {
                if (!mints[i].gameObject.activeSelf) mints[i].gameObject.SetActive(true);
                mints[i].GetOptions().IsReversal = isReversal;
                mints[i].Stop();
            }
        }
    }
}
